package logic

import (
	"context"
	"github.com/jinzhu/copier"
	"time"
	"xialou_platform/services/wallet/model"

	"xialou_platform/services/wallet/rpc/internal/svc"
	"xialou_platform/services/wallet/rpc/walletClient"

	"github.com/zeromicro/go-zero/core/logx"
)

type WalletUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewWalletUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WalletUpdateLogic {
	return &WalletUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 钱包入账与支出
func (l *WalletUpdateLogic) WalletUpdate(in *walletClient.WalletParam) (*walletClient.EmptyBody, error) {
	wallet := &model.Wallet{}
	copier.Copy(wallet, in)
	wallet.CreateTime = time.Unix(in.CreateTime, 0)
	wallet.UpdateTime = time.Now()
	err := l.svcCtx.WalletModel.Update(l.ctx, wallet)
	if err != nil {
		return nil, err
	}

	return &walletClient.EmptyBody{}, nil
}
